package com.burpee.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.burpee.dao.GroupMemberDao;
import com.burpee.dao.GroupsDao;
import com.burpee.ui.GroupMember;
import com.burpee.ui.Groups;
import com.burpee.ui.Member;

@Service(value="groupsService")
@Transactional
public class GroupsServiceImpl implements GroupsService {

	@Autowired
	GroupsDao groupsDao;
	
	@Autowired
	GroupMemberDao groupMemberDao;
	
	public List<Groups> list(int currentPage, int onepageCount) {
		
		return groupsDao.list(currentPage,onepageCount);
	}

	public Groups view(long groupNo) {
		// TODO Auto-generated method stub
		return groupsDao.view(groupNo);
	}
	
	

	public Groups memberview(String memberId) {
		
		return groupsDao.memberview(memberId);
	}

	@Transactional(propagation = Propagation.REQUIRED)
	public boolean add(Groups groups, Member member) {
		long groupNo = 0;
		groups.setGroupPoint(member.getHealthpointTotal());
		groupNo = groupsDao.add(groups);
		if(groupNo > 0){
			GroupMember groupMember = new GroupMember();
			groupMember.setGroupNo(groups.getGroupNo());
			groupMember.setMemberId(member.getMemberId());
			groupMember.setGroupMemberAccept("Y");
			groupMember.setGroupMemberRole("G");
			
			
			if(groupMemberDao.add(groupMember) > 0) {
				
				return true;
			} else {
				return false;
			}
			
		}
		else{

			return false;
		}
	}

	public boolean modify(Groups groups) {
		if(groupsDao.modify(groups) > 0){
			return true;
		}
		else{

			return false;
		}
	}

	public boolean remove(long groupNo) {
		if(groupsDao.remove(groupNo) > 0){
			return true;
		}
		else{

			return false;
		}
	}
	public int countgroups() {
		return groupsDao.countgroups();
	}
	
	public Groups groupcheck(String memberId) {
		return groupsDao.groupcheck(memberId);
	}

}
